<?php 

class KefuguanliTable extends We7Table {

    protected $tableName;
    private $page;

    public function __construct() {
        parent::__construct();
        $this->tableName = 'szxh_nmyx_activeexpirty_kefuguanli';
        $this->page = '';
    }

    public function getList($page = 1) {
        $size = 2;
        $list = $this->query
                     ->from($this->tableName)
                     ->orderby('uid', 'DESC')
                     ->page($page, $size)
                     ->getall();
        $total = $this->query->getLastQueryTotal();
        $this->page = pagination($total, $page, $size);
        return $list;
        // return pdo_getall('szxh_nmyx_activeexpirty_kefuguanli', [], [], 'uid');
    }

    public function pageHtml() {
        return $this->page;
    }

    public function findRow($uid) {

        return $this->query->from($this->tableName)->where('uid', $uid)->get();

    }

    public function addData($data) {
        if(strlen($data['name'])>12) {
            return message('长度不能超过4个字', 'refresh', 'error');
        }
        if(empty($data['name'])) {
            return message('名字不能为空', 'refresh', 'error');
        }

        if(empty($data['phonenum'])) {
            return message('号码不能为空', 'refresh', 'error');
        }
        if(strlen($data['phonenum'])>'11') {
            return message('手机号码不能超过11位', 'refresh', 'error');
        }

        $res = pdo_insert('szxh_nmyx_activeexpirty_kefuguanli',array('name' => $data['name'],
            'phonenum' => $data['phonenum']));

        return $res;
    }

    public function upData($data) {
        if(strlen($dataone['name'])>12) {
            return message('长度不能超过4个字', 'refresh', 'error');
        }
        if(empty($dataone['name'])) {
            return message('名字不能为空', 'refresh', 'error');
        }

        if(empty($dataone['phonenum'])) {
            return message('号码不能为空', 'refresh', 'error');
        }
        if(strlen($dataone['phonenum'])>'11') {
            return message('手机号码不能超过11位', 'refresh', 'error');
        }

        $res = pdo_update('szxh_nmyx_activeexpirty_kefuguanli', array(
            'name' => $dataone['name'],
            'image' => $dataone['image'],
            'phonenum' => $dataone['phonenum']
        ),array('uid' => $_POST['uid']));

        return $res;
    }

    public function delDate($date) {
        foreach ($date as $value) {
            $del = pdo_delete('szxh_nmyx_activeexpirty_kefuguanli',array('uid'=>$value));
        } 
            return $del;
    }

}